import { Component } from 'react'
import Taro from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import './index.scss'
import global from '../../global';
import { Textarea, Button, Map, Swiper, SwiperItem, Picker, Input, Image } from '@tarojs/components'
import Request from "../../api";
import Event from "../../event";
export default class Index extends Component {

  constructor(props) {
    super(props);
    this.state = {
      jobs: [],
    };
    this.loadJobs = this.loadJobs.bind(this);

  }

  componentWillMount () {
    this.loadJobs();
  }

  componentWillUnmount () {}

  componentDidHide () { }

  async loadJobs() {
    try {
      let res = await Request.get('/business/job_apply/list?userId=' + Number(global.userInfo.userId));
      if (res.data.code !== 200) {
        throw new Error();
      }
      this.setState({
        jobs: res.data.rows
      })
    } catch (e) {
      console.log('加载职位数据失败')
    }
  }

  render () {

    let  {jobs} = this.state;
    return (
      <View className='apply_info_list'>
        {
          jobs.length !== 0 ? jobs.map(item => {
            return (
              <View className='apply_info_item' onClick={async () => {
                global.currentApplyJob = item;
                global.isApplyJob = true;
                await Taro.navigateTo({
                  url: '/pages/job_detail/index'
                })
              }}>

                <View className='row'>
                  <Text className='job_name'>{item.name}</Text>
                  <Text className='job_salary'>{item.salary}</Text>
                </View>
                <View className='row'>
                  <Text className='job_experience'>{item.experience} {item.education} {item.masterType === '0' ? '个人招聘' : '企业招聘' } </Text>
                  <Text className='job_status' style={{color: item.status === '1' ? 'green' : 'red'}}>{item.status === '1' ? '招聘中' : '停止招聘'}</Text>
                </View>
                <View className='row'>
                  <View className='master_info'>
                    <Image src={require('./img/user.png')}/>
                    <Text>{item.masterType === '0' ? item.wxUserName : item.companyName}</Text>
                  </View>
                  <View className='action_container'>
                    <Text className='size28 color-green'>投递成功</Text>
                  </View>
                </View>
                <View className='row flex_end'>
                  <Text className='size28 job_experience'>{item.createTime}</Text>
                </View>
              </View>
            );
          })
            :
            <View className='message_container'>
              您暂未投递过任何岗位
            </View>
        }
      </View>
    )
  }
}
